﻿using System.Windows.Controls;
using System.Windows.Input;
using SilverlightApplication.LanguageResources;
using SilverlightApplication.UIControls;
using LinqToAmazonSL;

namespace SilverlightApplication
{
	public partial class BookBasicPanel : UserControl, ISearchPanelContent
	{
        SearchPanels parent;

		public BookBasicPanel(SearchPanels parent)
		{
			// Required to initialize variables
			InitializeComponent();

            bsTitle.Text = LanguageLoader.GetString("bsTitle");
            bsAuthor.Text = LanguageLoader.GetString("bsAuthor");

            this.parent = parent;
		}

        public SearchCriteria GetSearchCriteria()
        {
            SearchCriteria criteria = new SearchCriteria();
            AmazonBook book = new AmazonBook();

            book.Title = txbBookTitle.Text.Trim();
            book.Author = txbBookAuthor.Text.Trim();
            criteria.OrderBy = OrderClass.None;
            criteria.Item = book;

            return criteria;
        }

        public bool FieldsValidate()
        {
            return !txbBookTitle.Text.Equals(string.Empty) || !txbBookAuthor.Text.Equals(string.Empty);
        }

        public void ClearFields()
        {
            txbBookTitle.Text = "";
            txbBookAuthor.Text = "";
        }

        private void KeyPress(object sender, KeyEventArgs e)
        {
            if (Key.Enter.Equals(e.Key))
            {
                parent.beginSearch();
            }
        }
	}
}